package com.saile.service;

import com.saile.dao.NewsMapper;
import com.saile.domain.News;
import com.saile.myRunTime.MyRunTimeExcption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by Baggio on 2018-4-24.
 */
@Service
public class NewsServiceImpl extends BaseService implements NewsService {
    @Autowired
    NewsMapper newsMapper;

    private void insertNews(News news) {
        newsMapper.insertNews(news);
    }

    private void updateNews(News news) {
        newsMapper.updateNewsByPrimaryKeySelective(news);
    }

    @Override
    public void modifyNews(News news) throws MyRunTimeExcption {
        if (news.getTid() == null) {
            insertNews(news);
            return;
        }
        updateNews(news);
    }

    @Override
    public void deleteNews(Long newsId) throws MyRunTimeExcption {
        newsMapper.deleteNews(newsId);
    }

    @Override
    public List<News> getNewsRecommendList(Map<String, String> map) throws MyRunTimeExcption {
        return newsMapper.getNewsRecommendList(map);
    }

    @Override
    public List<News> getNewsList(Map<String, String> map) throws MyRunTimeExcption {
        return newsMapper.getNewsList(map);
    }

    @Override
    public News getNews(Map<String, String> map) throws MyRunTimeExcption {
        return newsMapper.getNews(map);
    }
}
